package com.agile.leetcode.bigdecimal;

import java.math.BigDecimal;

/**
 * @author CZK
 * @date 2022/7/25 13:59
 */
public class Demo2 {
    public static void main(String[] args) {
        BigDecimal amount1=new BigDecimal(0.02);
        BigDecimal amount2=new BigDecimal(0.03);
        // .0099999999999999984734433411404097569175064563751220703125
        // The results of this constructor can be somewhat unpredictable. One might assume that writing new BigDecimal(0.1)
        // in Java creates a BigDecimal which is exactly equal to 0.1 (an unscaled value of 1, with a scale of 1),
        // but it is actually equal to 0.1000000000000000055511151231257827021181583404541015625.
        // This is because 0.1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus,
        // the value that is being passed in to the constructor is not exactly equal to 0.1, appearances notwithstanding.
        // 结果不可预测
        System.out.println(amount2.subtract(amount1));
    }
}
